import gameConfig from "../../engines/configs/gameConfig";
import O1HD from "../../engines/gameEngine";
import { REWARD_TYPE } from "../../engines/services/userContent/userInterface";
import level_bunchbunchbunch from "../../levelBundles/level_bunchbunch/leve_bunchbunchbunch";
import { GAME_EVENT } from "../Enum";
import mainRoot from "../MainRoot";
import InGamePage from "./InGamePage";

const {ccclass, property} = cc._decorator;

@ccclass
export default class bunchInGamePage extends InGamePage {

    @property({type:cc.Label,tooltip:"时间文本"})
    lbTime:cc.Label = null;

    @property({type:cc.Node,tooltip:"提示按钮"})
    hintLb:cc.Node = null;

    level:level_bunchbunchbunch = null;

    bindLevel(level:level_bunchbunchbunch){
        this.level = level;
        this.refrenshCountDown();
    }

    refrenshCountDown(){
        let time = this.level.countDown;
        this.lbTime.string = time.toString();
    }

    hideTipsBtn(){
        this.tipBtn.active = false;
        this.hintLb.active = true;
    }

    OnTipsBtn(): void {
        O1HD.getManagers().soundMgr.playSound('mainSound/anNiu').then();
        if(O1HD.getServices().userSrv.getCoins() >0){
            O1HD.getServices().userSrv.setCoins(-1,true);
            O1HD.emit(GAME_EVENT.ON_BTN_TIPS);
        }else{
            O1HD.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(()=>{
                O1HD.emit(GAME_EVENT.ON_BTN_TIPS);
            },()=>{

            },null,"串串串看广告获得提示");
        }
    }

    onBtnInitGame(){
        O1HD.getManagers().soundMgr.playSound('mainSound/anNiu').then();
        let needPower:number = this.level.getLevelInfo()["subPower"] || 1;
        if(O1HD.getServices().userSrv.getPower() - needPower < 0){
            mainRoot.UIModel.showUserPropGet(REWARD_TYPE.POWER,gameConfig.ADD_ONCE_POWER);
            return;
        }
        O1HD.getServices().userSrv.setPower(-needPower,true,true);
        this.level.countDown = Number(this.level.levelData["time"]);
        this.level.initGame();
    }

}
